<template>
	<view class="bankCard-wrap">
		<view class="box1" v-for="(item, index) in dataList" :key="index" @click="bankCardClick(item)">
			<view lines="1" class="word1">{{ item.openBank }}</view>
			<view lines="1" class="word2">{{ item.name }}</view>
			<view lines="1" decode="true" class="txt2">****&nbsp;&nbsp; ****&nbsp;&nbsp; ****&nbsp;&nbsp; {{ item.bankNo.substring(item.bankNo.length-4) }}</view>
		</view>

		<u-empty-state v-if="dataList.length == 0" value="你还没有添加银行卡"></u-empty-state>
		<u-bottom-button value="添加银行卡" @click="gotoRouter('/pages-doctor/addBankCard/addBankCard')"></u-bottom-button>
	</view>
</template>

<script>
import uBottomButton from '@/components/u-bottom-button/u-bottom-button.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
import { mapState, mapMutations } from 'vuex';
export default {
	components: {
		uBottomButton,
		uEmptyState
	},
	data() {
		return {
			pageType: null, // null展示模式  1选择模式
			id: null,
			dataList: null
		};
	},
	onLoad(option) {
		this.pageType = option.type ? option.type : null;
	},
	onShow() {
		this.queryDoctorBankList();
	},
	methods: {
		...mapMutations({
			setUserBankCard: 'setUserBankCard'
		}),

		//选择
		selectAddress(item) {
			this.setUserBankCard(item);
			uni.navigateBack({
				delta: 1
			});
		},

		bankCardClick(item) {
			if (!this.pageType) {
				this.gotoRouter('/pages-doctor/addBankCard/addBankCard?id=' + item.id);
			} else {
				this.selectAddress(item);
			}
		},

		//列表
		queryDoctorBankList() {
			this.$api.queryDoctorBankList({}).then(res => {
				if (res.code == 200) {
					this.dataList = res.result.records;
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				}
			});
		}
	}
};
</script>

<style lang="less">
@import './bankCard.less';
</style>
